<template>
  <a-card :bordered="false" class="card-area">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-form layout="inline">
            <a-form-item label="名称">
              <a-input autocomplete="off" placeholder="请输入名称查询" v-model="queryParam.name.value"></a-input>
            </a-form-item>
            <a-form-item label="机构">
              <ak-tree-select-multiple
                :url="sysDepartUrl.tree"
                v-model="queryParam.depart.value"/>
            </a-form-item>
            <a-form-item label="创建时间">
              <ak-date-time-picker v-model="queryParam.createTime_begin.value"></ak-date-time-picker>
              ~
              <ak-date-time-picker v-model="queryParam.createTime_end.value"></ak-date-time-picker>
            </a-form-item>
            <a-form-item>
          <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button  @click="searchReset">重置</a-button>
              <a-upload  v-has="'SYS:ROLE:ADD'"
                         :showUploadList="false"
                         :customRequest="customImportRequest"
                         accept=".xls,.xlsx">
                <a-button  type="primary" :loading="importLoading" icon="import">导入</a-button>
              </a-upload>

              <a-button
                type="primary"
                icon="export"
                @click="handleExport">
                <span v-if="!exporting">导出</span>
                <a-progress v-if="exporting" :percent="exportPercent" size="small" status="active"/>
              </a-button>
              <a-button  v-has="'SYS:ROLE:ADD'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
              <a-button  type="danger" icon="delete" v-has="'SYS:ROLE:DEL'" v-if="selectedRowKeys.length > 0"  @click="batchDel">批量删除</a-button>
          </span>
            </a-form-item>
      </a-form>
    </div>


    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择&nbsp;<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <span slot="ellipsis" slot-scope="text">
          <ak-ellipsis :value="text" :length="25"/>
        </span>
        <span slot="filePrevies" slot-scope="text">
          <AkFilePreview :value="text"></AkFilePreview>
        </span>
        <span slot="action" class="table-operator" slot-scope="text, record">
          <a v-has="'SYS:ROLE:EDIT'"  @click="handleEdit(record)">编辑</a>

          <a v-has="'SYS:ROLE:EDIT'"  @click="handlePerssion(record)">授权</a>
          <a v-has="'SYS:ROLE:EDIT'" @click="handleUser(record.id)">用户</a>
          <a v-has="'SYS:ROLE:DEL'" v-if="record.buildInFlag != 'TRUE'" @click="handleDelete(record.id)">删除</a>
        </span>


      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
    <role-permission-modal ref="rolePermission" @ok="modalFormOk"></role-permission-modal>
    <role-user-list  ref="roleUserList"></role-user-list>
  </a-card>
</template>

<script>
  import RoleModal from './modules/RoleModal'
  import  AkfhListMixin  from '../../mixin/AkfhListMixin';
  import RolePermissionModal from './modules/RolePermissionModal';
  import {sysDepartUrl, sysRoleUrl} from '../../api/url';
  import RoleUserList from './modules/RoleUserList'
  import AkTreeSelectMultiple from "../../components/akfh/AkTreeSelectMultiple";
  import AkEllipsis from "../../components/akfh/AkEllipsis"
  import AkDateTimePicker from "../../components/akfh/AkDateTimePicker";
  import AkFilePreview from '../../components/akfh/file-preview/AkFilePreview'

  export default {
    name: "RoleList",
    mixins:[AkfhListMixin],
    components: {
      AkFilePreview,
      AkDateTimePicker,
      AkTreeSelectMultiple,
      RoleUserList,
      RoleModal,
      RolePermissionModal,
      AkEllipsis
    },
    data () {
      return {
        departTree:[],
        description: '角色管理页面',
        // 查询条件
        queryParam: {
          name:{
            column:'name',
            type: 'like',
            value: ''
          },
          depart:{
            column:'sysDepart.id',
            type:'in',
            value:''
          },
          createTime_begin:{
            column:'createDateTime',
            type: 'gt',
            value: ''
          },
          createTime_end:{
            column:'createDateTime',
            type: 'lt',
            value: ''
          }
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '角色名称',
            align:"center",
            dataIndex: 'name',
            scopedSlots: { customRender: 'ellipsis' },
          },
          {
            title: '角色编码',
            align:"center",
            dataIndex: 'code',
            scopedSlots: { customRender: 'ellipsis' },
          },
          {
            title: '机构',
            align:"center",
            dataIndex: 'sysDepartName',
            scopedSlots: { customRender: 'ellipsis' },
          },
          {
            title: '备注',
            align:"center",
            dataIndex: 'description',
            scopedSlots: { customRender: 'ellipsis' },
          },
          {
            title: '创建时间',
            dataIndex: 'createDateTime',
            align:"center",
            sorter: true
          },

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: sysRoleUrl,
        sysDepartUrl:sysDepartUrl,
      }
    },


    methods: {
      handlePerssion: function(record){
        this.$refs.rolePermission.show(record.id, record.permissionListIds);
      },
      handleUser: function (roleId) {
        this.$refs.roleUserList.show(roleId);
      },
    }
  }
</script>
<style scoped>
</style>
